import { Inject, Injector, ICommandService, UniverInstanceType, Plugin } from "@univerjs/core";
import { ComponentManager, IMenuManagerService, ContextMenuPosition, ContextMenuGroup, RibbonStartGroup } from "@univerjs/ui";
import { getRangeProtectionPoint } from "./commands";
import { getRangeProtectionPointMenu } from "./toggle-menu";
import { CopySingle } from "@univerjs/icons";

const SHEET_CUSTOM_MENU_PLUGIN = "SHEET_CUSTOM_MENU_PLUGIN";

export class UniverSheetsCustomMenuPlugin extends Plugin {
  static override type = UniverInstanceType.UNIVER_SHEET;
  static override pluginName = SHEET_CUSTOM_MENU_PLUGIN;

  constructor(
    _config: null,
    @Inject(Injector) private readonly _injector: Injector,
    @ICommandService private readonly _commandService: ICommandService,
    @IMenuManagerService private readonly _menuManagerService: IMenuManagerService,
    @Inject(ComponentManager) private readonly _componentManager: ComponentManager
  ) {
    super();
  }
  override onStarting(): void {
    [getRangeProtectionPoint].forEach(c => {
      this.disposeWithMe(this._commandService.registerCommand(c));
    });
    this.disposeWithMe(this._componentManager.register("CopySingle", CopySingle));
    this._menuManagerService.mergeMenu({
      [RibbonStartGroup.OTHERS]: {
        [getRangeProtectionPoint.id]: {
          order: 0,
          menuItemFactory: getRangeProtectionPointMenu
        }
      },
      [ContextMenuPosition.MAIN_AREA]: {
        [ContextMenuGroup.OTHERS]: {
          [getRangeProtectionPoint.id]: {
            order: 0,
            menuItemFactory: getRangeProtectionPointMenu
          }
        }
      }
    });
  }
}
